import { getApiList, getRuleList, getDictionaryTypeList } from '../../../../service'
import { validateNotJSkeyWord } from '../../../../../../../../common/utils/validate'

let variableValidator = (rule, value, callback) => {
  const re = /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z\d_\u4e00-\u9fa5]*$/
  if (!re.test(value)) {
    callback(new Error('字段名必须以字母开头，且只能包含字母、数字、下滑线）'))
    return
  }
  if (!validateNotJSkeyWord(value)) {
    callback(new Error('不能使用js保留字段'))
    return
  }
  callback()
}
export default {
  labelWidth: '94px',
  gap: '12px',
  groupTheme: 'collapse',
  groups: [
    {
      title: '组件配置',
      columnsCount: 2,
      items: [
        {
          label: '标识',
          prop: 'componentId',
          readonly: true
        },
        {
          label: '绑定方法',
          prop: 'bindMethod',
          type: 'radio',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [
              {
                label: '字典',
                value: 1
              },
              {
                label: '输入',
                value: 2
              }
            ]
          }
        },
        {
          type: 'select',
          label: '关联字典',
          prop: 'propertyType',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getDictionaryTypeList()
            }
          },
          rules: [{ required: true, message: '请选择绑定值类型', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'bindSelect',
          label: '绑定值',
          prop: 'propertyName',
          config: {
            bindProp: 'propertyType',
            optionsValueKey: 'tagValue',
            optionsLabelKey: 'dicTagName',
            returnObject: false,
          },
          rules: [{ required: true, message: '请选择绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '绑定值',
          prop: 'propertyName',
          rules: [{ required: true, message: '请输入绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 2) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '名称',
          prop: 'name',
          rules: [{ required: true, message: '请输入控件名称', trigger: 'blur' }]
        },
        {
          label: '提示语',
          prop: 'placeholder'
        },
        {
          type: 'bindLabel',
          label: '标签',
          prop: 'label',
          readonly: true,
          config: {
            bindProp: 'propertyName',
            subordinateProp: 'propertyType'
          },
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '标签',
          prop: 'label',
          exist(value) {
            if (value.bindMethod === 2) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          // label: '',
          // labelWidth: '0',
          prop: 'inputType',
          label: '类型',
          required: true,
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [{ label: '输入框', value: 'text' }, { label: '文本框', value: 'textarea' }]
          },
          rules: [{ required: true, message: '请选择输入框类型', trigger: 'change' }],
          exist(value) {
            if (!value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          label: '输入方式',
          prop: 'inputWay',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [{ label: '用户输入', value: 'custom' }, { label: '同步关联', value: 'syncLink' }]
          },
          rules: [{ required: true, message: '请选择输入方式', trigger: 'change' }],
          exist(value) {
            if (!value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          label: '连接类型',
          prop: 'connectType',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [
              { label: '数据字典', value: 'dictionary' },
              { label: '数据接口', value: 'interface' }
            ]
          },
          rules: [{ required: true, message: '请选择连接类型', trigger: 'change' }],
          exist(value) {
            if (value.inputWay === 'asyncLink' && !value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          label: '数据字典',
          prop: 'dataDictionaryId',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getDictionaryTypeList()
            }
          },
          exist(value) {
            if (value.inputWay === 'asyncLink' && value.connectType === 'dictionary') {
              return true
            } else {
              return false
            }
          },
          rules: [{ required: true, message: '请选择数据字典', trigger: 'change' }]
        },
        {
          type: 'select',
          label: '数据接口',
          prop: 'dataInterfaceId',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getApiList()
            }
          },
          rules: [{ required: true, message: '请选择数据接口', trigger: 'change' }],
          exist(value) {
            if ((value.inputWay === 'asyncLink' && value.connectType === 'interface') || value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '',
          labelWidth: '0',
          prop: 'linkSearchQueryKey',
          config: {
            label: '查询参数名'
          },
          exist(value) {
            if ((value.inputWay === 'asyncLink' && value.connectType === 'interface' && !value.isFilter)) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '',
          labelWidth: '0',
          config: {
            label: '查询值表达式'
          },
          prop: 'linkSearchEx',
          exist(value) {
            if ((value.inputWay === 'asyncLink' && value.connectType === 'interface' && !value.isFilter)) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '',
          labelWidth: '0',
          config: {
            label: '关联表达式',
            required: true
          },
          prop: 'linkEx',
          rules: [{ required: true, message: '请输入关联表达式', trigger: 'blur' }],
          exist(value) {
            if (value.inputWay === 'syncLink' && !value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          label: '校验规则',
          prop: 'patterns',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getRuleList()
            }
          },
          exist(value) {
            if (!value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '',
          labelWidth: '0',
          prop: 'maxlength',
          config: {
            label: '最大输入长度',
            type: 'number'
          },
          exist(value) {
            if (!value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '后缀',
          prop: 'suffix',
          exist(value) {
            return value.inputType === 'text' && !value.isFilter
          }
        },
        {
          type: 'select',
          label: '类型',
          prop: 'type',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [{ label: '请求参数', value: 'param' }, { label: '前端过滤', value: 'normal' }]
          },
          rules: [{ required: true, message: '请选择单选样式', trigger: 'change' }],
          exist(value) {
            if (value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '',
          labelWidth: '0',
          prop: 'paramName',
          config: {
            required: true,
            label: '请求参数名',
            placeholder: '多个参数名用\',\'分隔'
          },
          exist(value) {
            if (value.type === 'param' && value.isFilter) {
              return true
            } else {
              return false
            }
          },
          rules: [{ required: true, message: '请选择类型', trigger: 'blur' }]
        },
        {
          label: '列表字段',
          prop: 'listKey',
          exist(value) {
            if (value.type === 'normal' && value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },
        {
          label: '过滤字段',
          prop: 'filterKeys',
          config: {
            placeholder: '多个过滤字段用\',\'分隔'
          },
          rules: [{ required: true, message: '请输入过滤字段', trigger: 'blur' }],
          exist(value) {
            if (value.type === 'normal' && value.isFilter) {
              return true
            } else {
              return false
            }
          }
        },

        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: '失去焦点回调',
            height: '300px',
            lineNumbers: 'on',
            position: 'right'
          },
          prop: 'blurCb'
        },
        // {
        //   type: 'commonConfigEditor',
        //   config: {
        //     marginLeft: -80,
        //     lineNumbers: 'on',
        //     title: '详情模式',
        //     position: 'right'
        //   },
        //   label: '详情模式',
        //   prop: 'isDetailMode'
        // },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否必填',
            position: 'right'
          },
          label: '是否必填',
          prop: 'required'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否可见',
            position: 'right'
          },
          label: '是否可见',
          prop: 'isShowExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否存在',
            position: 'right'
          },
          label: '是否存在',
          prop: 'isExistExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            height: '300px',
            lineNumbers: 'on',
            title: '是否只读',
            position: 'right'
          },
          label: '是否只读',
          prop: 'isReadonlyExp'
        }
      ]
    }, /* {
      title: '组件事件',
      columnsCount: 2,
      items: [
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: 'keydown',
            height: '300px',
            lineNumbers: 'on',
            position: 'right',
            haveIcon: true
          },
          prop: 'keydownCb'
        },
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: 'keyup',
            height: '300px',
            lineNumbers: 'on',
            position: 'right',
            haveIcon: true
          },
          prop: 'keyupCb'
        },
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: 'focus',
            height: '300px',
            lineNumbers: 'on',
            position: 'right',
            haveIcon: true
          },
          prop: 'focusCb'
        },
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: 'input',
            height: '300px',
            lineNumbers: 'on',
            position: 'right',
            haveIcon: true
          },
          prop: 'inputCb'
        }
      ]
    } */
  ]

}
